package com.renwei.yunlong.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.renwei.yunlong.R;
import com.renwei.yunlong.bean.UpcomingBean;
import com.renwei.yunlong.utils.DateTimeUtils;
import com.zyf.fwms.commonlibrary.base.baseadapter.BaseRecyclerViewAdapter;

import io.github.xudaojie.qrcodelib.zxing.DensityUtils;


/**
 * 我的待办  问题 adapter
 * <p>
 * Created by Administrator on 2017/9/7.
 */

public class DealProblemAdapter extends BaseRecyclerViewAdapter<UpcomingBean.Rows> {

    public DealProblemAdapter(Context context) {
        super(context);
    }

    @Override
    public MeUpcomingProblemViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = inflater.inflate(R.layout.item_me_upcoming_work, parent, false);
        return new DealProblemAdapter.MeUpcomingProblemViewHolder(view);
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder rholder, final int position) {
        MeUpcomingProblemViewHolder holder = (MeUpcomingProblemViewHolder) rholder;

        RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(
                RelativeLayout.LayoutParams.MATCH_PARENT, DensityUtils.dp2px(mContext,60));
        if (position==0){
            params.setMargins(0, DensityUtils.dp2px(mContext,10),0,0);
        }else {
            params.setMargins(0, 0,0,0);
        }
        holder.itemView.setLayoutParams(params);

        final UpcomingBean.Rows rows = mList.get(position);

        holder.tvTitleContent.setText(rows.getContent());
        holder.tvDepartment.setText(rows.getServerName());
        if (!TextUtils.isEmpty(rows.getSendUserName())) {
            holder.tvName.setText("/" + rows.getSendUserName());
        }

        holder.tvOverdue.setVisibility(View.GONE);
        String DateTimeStr = rows.getCompleteDate();
        if (!TextUtils.isEmpty(DateTimeStr)) {
            holder.tvTime.setVisibility(View.VISIBLE);
            holder.tvTime.setText(DateTimeUtils.stampToDateNow(DateTimeUtils.string2Long(DateTimeStr, "yyyy-MM-dd HH:mm:ss")));
        }

        if ("2".equals(rows.getKind())) {
            if ("4".equals(rows.getNowStat())) {
                holder.button.setBackgroundResource(R.drawable.shape_card_e64545);

                holder.button.setText("待申领");
            } else if ("1".equals(rows.getNowStat())) {
                holder.button.setBackgroundResource(R.drawable.shape_card_e9981f);
                holder.button.setText("处理中");
            } else if ("2".equals(rows.getNowStat())) {
                holder.button.setBackgroundResource(R.drawable.shape_card_e64545);
                holder.button.setText("待确认");
            } else if ("3".equals(rows.getNowStat())) {
                holder.button.setBackgroundResource(R.drawable.shape_card_e64545);
                holder.button.setText("未解决");
            } else if ("6".equals(rows.getNowStat())) {
                holder.button.setBackgroundResource(R.drawable.shape_card_e64545);
                holder.button.setText("已解决");
            } else if ("-6".equals(rows.getNowStat())) {
                holder.button.setBackgroundResource(R.drawable.shape_card_e64545);
                holder.button.setText("审核未通过");
            } else if ("7".equals(rows.getNowStat())) {
                holder.button.setBackgroundResource(R.drawable.shape_card_999691);
                holder.button.setText("已关闭");
            }
        }

        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mOnItemClickLitener.onItemClick(v, position);
            }
        });
    }

    static class MeUpcomingProblemViewHolder extends RecyclerView.ViewHolder {

        private View itemView;
        private TextView tvTitleContent;//标题内容
        private TextView tvDepartment;//部门
        private TextView tvName;//用户名
        private TextView tvTime;//时间
        private TextView tvOverdue;//逾期
        private TextView button;//状态按钮

        public MeUpcomingProblemViewHolder(View view) {
            super(view);
            itemView = view;
            tvTitleContent = itemView.findViewById(R.id.tv_title_content);
            tvDepartment = itemView.findViewById(R.id.tv_department);
            tvName = itemView.findViewById(R.id.tv_name);
            tvTime = itemView.findViewById(R.id.tv_time);
            tvOverdue = itemView.findViewById(R.id.tv_overdue);
            button = itemView.findViewById(R.id.button);
        }
    }
}
